#include "kuaicu.h"
#include <iostream>

void sumSinglePassF(int size, int blocks, int threads, 
	const float d_idata[], int inc, float d_odata[]);

namespace kuai { namespace cuda { 

	float FloatArray::sum() const {
		int n = size();
		int blocks, threads;
		getNumBlocksAndThreads(n, blocks, threads);
		FloatArray output(blocks);

		std::cout << n << "\t" << blocks << "\t" 
			<< threads << "\t" << skip() << std::endl;
		sumSinglePassF(n, blocks, threads, c_pointer(), skip(), output.c_pointer());
		float result;
		std::vector<float> tt;
		output.get(tt);
		for (size_t i = 0; i < tt.size(); ++i) {
			std::cout << tt[i] << std::endl;
		}
		CUDA_SAFE_CALL( cudaMemcpy(&result,
			output.c_pointer(), sizeof(float), cudaMemcpyDeviceToHost) );
		return result;
	}

}}

